package fasilkom.antz.gui;

import com.golden.gamedev.Game;
import com.golden.gamedev.object.Sprite;

import fasilkom.antz.Antz;
import fasilkom.antz.GameChar;


public class RecruitButton extends Button {

	public static final int PLAYERS_MAX = 8;

	public static int[] antsNeeded = {10, 30};
	
	private Antz main;
	private int level;
	private int type;
	
	/**
	 * Konstruktor button untuk rekrutmen.
	 * @param main main game, yakni {@link Antz}
	 * @param level level dari tentara, dimulai dari 0
	 * @param x lokasi button
	 * @param y lokasi button
	 * @param w lebar button
	 * @param h tinggi button
	 */
	public RecruitButton(Game main, int type, int level, int x, int y, int w, int h) {
		super("Recruit", x, y, w, h);
		this.main = (Antz) main;
		this.level = level;
		this.type = type;
	}

	@Override
	public void doAction() {
		super.doAction();
		
		// Count player
		int totalPlayer = 0;
		for (Sprite i : main.PLAYER_GROUP.getSprites()) {
			if (i != null && i.isActive())
				++totalPlayer;
		}
		
		if (main.antSaved >= antsNeeded[level] && totalPlayer < PLAYERS_MAX) {
			main.antSaved -= antsNeeded[level];
			
			GameChar newArmy = new GameChar(main, type, false);
			newArmy.setLocation(main.zee.getX(), main.zee.getY());
			main.PLAYER_GROUP.add(newArmy);
		}
	}
}
